@layout("/common/_curd/_container.html"){


<script type="text/javascript">

	$(function(){
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		$("#btn_close").bind("click",function(){
			parent.layer.close(index);
		});
		$("#btn_save").bind("click",function(){
			var id,name;
			if($(".nav li:first").hasClass("active")){
				//获取选中行(单行)的ID
				var arr = $(grid_selector).jqGrid("getGridParam", "selarrrow");
				if(arr.length>1){
					layer_alert('只能选择一条数据!', "warn");
	                return false;
				}
				id = $(grid_selector).jqGrid('getGridParam','selrow');
				if(!id){
					layer.msg("选项不能为空", {shift: 6});
					return false; 
				}

				//根据id获取行数据,返回的是列表

				var rowDatas = $(grid_selector).jqGrid('getRowData', id);

				//取到选中行某一字段的值，其中name为colModel中定义的字段名

				name = rowDatas["name"];
			}else{
				var zTree = $.fn.zTree.getZTreeObj("zTree");
				var nodes = zTree.getCheckedNodes();
				if(nodes.length<1){
					layer.msg("选项不能为空", {shift: 6});
					return false; 
				}
				id = nodes[0].id;
				name = nodes[0].name;
				
			}
            parent.$("#${index!}_INPUT").val(name);
            parent.$("#${index!}").val(id);
            parent.layer.close(index);
			

		});
		initGrid();
		initZtree();
	});
	
	function initZtree(){
		var setting = {
				check: {
					enable: true,
					@ if(check! == "radio"){
						chkStyle: "radio",
						radioType : "all"
					@ } else{
						chkboxType :{ "Y" : "", "N" : "" }
					@ }
				},
				data: {
					simpleData: {
						enable: true
					}
				}
			};
		
		
		
		$.post("${basePath}/ztree/getTreeList",{source:"${source!}", type:"${type!}", where:"${where!}", intercept:"${intercept!}", ext:"${x.ext!}", val:"${val!}"},function(data){
			if(data.code===0){
				$.fn.zTree.init($("#zTree"), setting, data.data);
			}
			else{
				layer_alert("数据加载失败", "error");
			}
		}, "json");
	}
	
	var ctx = "${basePath}";
	var grid_selector = "#grid-table";
	function initGrid(){
		var grid_url = ctx + "/teacher/list";
		var _colnames = ["ID", 
						"姓名"
						];
		var _colmodel = [{name:"id", index:"id", width:100,hidden:true},
						{name:"name", index:"name", width:100}
        ];
		
		jQuery(grid_selector).jqGrid({
			url : grid_url,
		    shrinkToFit : true,
			colNames : _colnames,
			colModel : _colmodel, 
			jsonReader : {id :"id"},
		    rowNum: 100,
		    rowList: [100],
			postData : {sort : "first_spell", order : "asc"}
		});
	}
	

	
	
</script>
     <div class="row">
         <div class="col-xs-12" style="padding-left:5px;">
             <ul class="nav nav-tabs" role="tablist">
                 <li class="active"><a href="#Index" role="tab" data-toggle="tab">按姓名</a></li>
                 <li ><a href="#Second" role="tab" data-toggle="tab">按组织机构</a></li>
             </ul>
             <div class="tab-content">
                 <div role="tabpanel" class="tab-pane active" id="Index">
					<!-- 配置grid -->
					<div class="row">
						<div class="col-sm-1"></div>
						<div class="col-sm-10">
							<div class="widget-box widget-color-blue2">
								<div class="widget-header">
									<h4 class="widget-title lighter smaller">${func.decodeUrl(name!)}</h4>
								</div>
				
								<div class="widget-body">
									<div class="widget-main padding-8">
										<!-- grid -->
										<table id="grid-table"></table>
									</div>
								</div>
							</div>
						</div>
						<div class="col-sm-1"></div>
					</div>
                 </div>
                 <div role="tabpane2" class="tab-pane" id="Second">
					<!-- 配置grid -->
					<div class="row">
						<div class="col-sm-1"></div>
						<div class="col-sm-10">
							<div class="widget-box widget-color-blue2">
								<div class="widget-header">
									<h4 class="widget-title lighter smaller">${func.decodeUrl(name!)}</h4>
								</div>
				
								<div class="widget-body">
									<div class="widget-main padding-8">
										<ul id="zTree" class="ztree"></ul>
									</div>
								</div>
							</div>
						</div>
						<div class="col-sm-1"></div>
					</div>
                 </div>
             </div>
         </div>
     </div>


	
	<div class="clearfix form-actions center" style="padding:0;">
		<div class="col-md-offset-1 col-md-10">
		  	<button class="btn btn-sm btn-info" type="button" id="btn_save">
				<i class="ace-icon fa fa-check bigger-110"></i>
				确定
			</button>

			&nbsp; &nbsp; &nbsp;
			<button class="btn btn-sm" type="button" id="btn_close">
				<i class="ace-icon fa fa-close bigger-110"></i>
				关闭
			</button>
		</div>
	</div>

	
		<!-- 引入所需的js -->
	 <script src="${basePath}/static/assets/js/jqGrid/jquery.jqGrid.src.js" type="text/javascript" ></script>
 <script src="${basePath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js" type="text/javascript" ></script>
 <script src="${basePath}/static/style/js/forlist.js" type="text/javascript" ></script>
 <script src="${basePath}/static/blade/js/blade-btn.js" type="text/javascript" ></script>
 
 <script src="${basePath}/static/assets/js/jquery.contextmenu.js" type="text/javascript" ></script>
 <script src="${basePath}/static/blade/js/blade-girdmenu.js" type="text/javascript" ></script>
	<!-- 引入所需js -->
	<link rel="stylesheet" href="${basePath}/static/zTree/css/zTreeStyle/zTreeStyle.css" />
	<script src="${basePath}/static/zTree/js/jquery.ztree.core.js" type="text/javascript" ></script>
	<script src="${basePath}/static/zTree/js/jquery.ztree.excheck.js" type="text/javascript"></script>
@}	